/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.usc.csci538.hw6.data;

import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author yaoli
 */
public class DefaultCalendarEntries {
    public static void register() {
        CalendarEntryManager cem = CalendarEntryManager.get();
        cem.reset();
        CalendarEntry entry;
        
        entry = new CalendarEntry();
        entry.setSubject("Meeting").setLocation("Library")
                .setStartTime(10, 15, true).setEndTime(11, 0, true);
        attachDate(entry, 0);
        cem.addEntry(entry);
        
        entry = new CalendarEntry();
        entry.setSubject("Dinner with Unico").setLocation("Fujisan Sushi")
                .setStartTime(7, 0, false).setEndTime(9, 0, false);
        attachDate(entry, 0);
        cem.addEntry(entry);
        
        entry = new CalendarEntry();
        entry.setSubject("Workout").setLocation("Gym")
             .setStartTime(9, 0, true).setEndTime(10, 0, true).setRepeat(CalendarEntry.REPEAT_DAILY);
        attachDate(entry, -10);
        cem.addEntry(entry);
        
        entry = new CalendarEntry();
        entry.setSubject("Movie at Charlie's").setLocation("Charlie's place")
             .setStartTime(8, 30, false).setEndTime(11, 30, false);
        attachDate(entry, 1);
        cem.addEntry(entry);
    }
    
    private static void attachDate(CalendarEntry entry, int daysFromToday) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(cal.getTime().getTime() - 8*60*60*1000L));
        long time = cal.getTime().getTime() + (daysFromToday * 24 * 60 * 60 * 1000L);
        cal.setTime(new Date(time));
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DATE);
        entry.setDate(year, month, day);
    }
}
